package com.chart.chart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chart.chart.domian.ChartConfigs;
import com.chart.chart.domian.ChartFiles;
import com.chart.chart.domian.ChartFilesNew;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户表 数据层
 *
 * @author ruoyi
 */
@Mapper
public interface ChartFilesMapper extends BaseMapper<ChartFiles> {


    List<ChartFiles> selectFilesByName(@Param("name") String name, @Param("userId") Long userId);

    List<ChartFiles> selectAllSubFolders(Long folderId, Long userId);

    int updateFolderParentId(@Param("folderId") Long folderId, @Param("targetParentId") Long targetParentId);

    // 确认 itemId 是否为文件夹
    boolean isFolderById(@Param("itemId") Long itemId);

    // 更新文件的 file_id
    int updateFileParentId(@Param("itemId") Long itemId, @Param("targetParentId") Long targetParentId);

    boolean isItemExists(@Param("itemId") Long itemId); // 检查文件或文件夹是否存在


    @Select("SELECT version FROM chart_files WHERE file_id = #{folderId}")
    Integer selectByfileId(@Param("folderId") Long folderId);


    @Update("UPDATE chart_files SET parent_id = #{targetParentId}," +
            " version = version + 1 " +
            "WHERE file_id = #{folderId} " +
            "AND user_id = #{userId} " +
            "AND version = #{version}")
    int updataParentId(
            @Param("folderId") Long folderId,
            @Param("targetParentId") Long targetParentId,
            @Param("userId") Long userId,
            @Param("version") Integer version
    );


}




